package top.gcl.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.gcl.entities.Notice;
import top.gcl.json.JsonResult;
import top.gcl.services.NoticeService;

import javax.annotation.Resource;

@RestController
@Slf4j
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @GetMapping(value="/getNoticeById/{id}")
    public JsonResult<Notice> getNoticeById(@PathVariable("id") String id){
        Notice notice=noticeService.getNoticeById(id);
        return new JsonResult(200,"成功！",notice);
    }
    //url后面没有/，client发请求时有没有/都可以。如果这里有/，那么client发请求时必须带上/
    @PostMapping(value="/sendNotice")
    public JsonResult sendNotice(@RequestBody Notice notice){
        noticeService.sendNotice(notice);
        log.info(String.format("%s 向 %s 发送通知成功！",notice.getFromUserid(),notice.getToUserid()));
        return new JsonResult(200,"成功！");
    }
}
